// 内存缓存
const memoryCache = {};

export function setCache(key, value) {
	memoryCache[key] = value;
	try {
		uni.setStorageSync(key, value);
	} catch (e) {}
}

export function getCache(key) {
	if (memoryCache[key] != null) return memoryCache[key];
	try {
		const v = uni.getStorageSync(key);
		if (v != null && v !== '') {
			memoryCache[key] = v;
			return v;
		}
	} catch (e) {}
	return null;
}

export async function preloadXingZuoData() {
	const cached = getCache('xingZuoData');
	if (cached) return cached;
	const mod = await import('../json/xingZuoData.json');
	const data = mod && (mod.default || mod);
	setCache('xingZuoData', data);
	return data;
}

export async function getXingZuoDetail() {
	const cached = getCache('xingZuoDetail');
	if (cached) return cached;
	const mod = await import('../json/xingZuoDetail.json');
	const data = mod && (mod.default || mod);
	setCache('xingZuoDetail', data);
	return data;
}

export async function getXingZuoPeiDui() {
	const cached = getCache('xingZuoPeiDui');
	if (cached) return cached;
	const mod = await import('../json/xingZuoPeiDui.json');
	const data = mod && (mod.default || mod);
	setCache('xingZuoPeiDui', data);
	return data;
}

